package com.muyu.product.domain;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.muyu.product.domain.model.CategoryInfoSaveModel;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import lombok.AllArgsConstructor;
import lombok.experimental.SuperBuilder;
import io.swagger.annotations.*;
import com.muyu.common.core.annotation.Excel;
import com.muyu.product.domain.req.CategoryInfoQueryReq;
import com.muyu.product.domain.req.CategoryInfoSaveReq;
import com.muyu.product.domain.req.CategoryInfoEditReq;
import com.muyu.common.core.web.domain.TreeEntity;

import java.util.Date;
import java.util.function.Function;
import java.util.function.Supplier;

/**
 * 品类信息对象 category_info
 *
 * @author DongZeLiang
 * @date 2024-02-27
 */
@Data
@SuperBuilder
@NoArgsConstructor
@AllArgsConstructor
@TableName("category_info")
@EqualsAndHashCode(callSuper = true)
@ApiModel(value = "CategoryInfo", description = "品类信息")
public class CategoryInfo extends TreeEntity {

    private static final long serialVersionUID = 1L;

    /** 主键 */
    @TableId(value = "id",type = IdType.AUTO)
    @ApiModelProperty(name = "主键", value = "主键")
    private Long id;

    /** 品类名称 */
    @Excel(name = "品类名称")
    @ApiModelProperty(name = "品类名称", value = "品类名称", required = true)
    private String name;

    /** 图片 */
    @Excel(name = "图片")
    @ApiModelProperty(name = "图片", value = "图片", required = true)
    private String image;

    /** 是否启用 */
    @Excel(name = "是否启用")
    @ApiModelProperty(name = "是否启用", value = "是否启用", required = true)
    private String start;

    /** 介绍 */
    @Excel(name = "介绍")
    @ApiModelProperty(name = "介绍", value = "介绍")
    private String introduction;

    /**
    * 查询构造器
    */
    public static CategoryInfo queryBuild( CategoryInfoQueryReq categoryInfoQueryReq){
        return CategoryInfo.builder()
                .name(categoryInfoQueryReq.getName())
                .image(categoryInfoQueryReq.getImage())
                .start(categoryInfoQueryReq.getStart())
                .introduction(categoryInfoQueryReq.getIntroduction())
                .build();
    }

    /**
    * 添加构造器
    */
    public static CategoryInfo saveBuild(CategoryInfoSaveReq categoryInfoSaveReq, Supplier<String> supplier){
        return CategoryInfo.builder()
                .name(categoryInfoSaveReq.getName())
                .image(categoryInfoSaveReq.getImage())
                .start(categoryInfoSaveReq.getStart())
                .introduction(categoryInfoSaveReq.getIntroduction())
                .parentId(categoryInfoSaveReq.getParentId())
                .createBy(supplier.get())
                .createTime(new Date())
                .build();
    }

    /**
    * 修改构造器
    */
    public static CategoryInfo editBuild(Long id, CategoryInfoEditReq categoryInfoEditReq){
        return CategoryInfo.builder()
            .id(id)
                .name(categoryInfoEditReq.getName())
                .image(categoryInfoEditReq.getImage())
                .start(categoryInfoEditReq.getStart())
                .introduction(categoryInfoEditReq.getIntroduction())
                .build();
    }

    public static CategoryInfo saveModelBuild(CategoryInfoSaveModel categoryInfoSaveModel) {
        return CategoryInfo.builder()
                .name(categoryInfoSaveModel.getName())
                .image(categoryInfoSaveModel.getImage())
                .start(categoryInfoSaveModel.getStart())
                .introduction(categoryInfoSaveModel.getIntroduction())
                .parentId(categoryInfoSaveModel.getParentId())
                .createBy(categoryInfoSaveModel.getCreateBy())
                .createTime(new Date())
                .build();
    }
}
